Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

295
Views
"Method Not Allowed The method is not allowed for the requested URL" even with methods = ["POST"] enabled?

In a render.html file I have a button that calls a function in render.js (I included render.js as src in script)

<button type="button" onclick="someFunc()">Calculate</button>

In render.js someFunc() makes a request

options =  {
        method: "POST",
        headers: {
           "Content-Type" : "application/json"
        },
        body: JSON.stringify(feat1dataObj)
    }

    const test1 = await fetch('http://localhost:5000/analyzeInput', options)

app.py is the backend that should handle the request

from flask import Flask, jsonify, request

app = Flask(__name__);

@app.route('/analyzeInput', methods = ['POST'] )
def analyzeData(res):
    part1Len = request.json['part1Len']
    print(part1Len);
    res = jsonify( {"Testing":"1"} )
    res.headers.add('Access-Control-Allow-Origin', '*')
    res.headers.set('Access-Control-Allow-Methods', 'GET, POST')
    return res;


#start server
if __name__ == "__main__":
    app.run(debug=True);

But I get 405 ""Method Not Allowed The method is not allowed for the requested URL"; the typical solution is that method = ["POST"] is not included but I have that.

GitBash terminal Output

Seems like I'm making a GET request somehow?

Overall, I'm using ElectronJS to make a GUI, just trying to pass data from the GUI to Python script to process, not sure why tutorials recommend hosting; seems like there should be a way a much simpler way to do this.

EDIT:

@app.route('/analyzeInput', methods = ['GET', 'POST', 'OPTIONS'] )
#def analyzeData(res):
#def analyzeData(request):
def analyzeData():
  if request.method == 'POST': 
    print("entered analyzeInput")
    #part1Len = request.json['part1Len']
    #print(part1Len);
    res = jsonify( {"Testing":"1"} )
    res.headers.add('Access-Control-Allow-Origin', '*')
    #res.headers.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
    res.headers.add('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
    return res;

Code currently looks like this (I changed analyzeData to analyzeInput; and changed it everywhere so I don't worry about that part). Getting "view function for 'analyzeData' did not return a valid response. The function either returned None or ended without a return statement" as the internal server error.

Again, pretty sure that the problem is that the request is sent as "GET" not "POST" but cannot find an explanation for this. New output

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

It's cross site origin(CORS) issue. From your code I can see you have already taking care of that but in the app.route add options like this: @app.route('/analyzeInput', methods = ['POST', 'OPTIONS'] ) . The reason is that the browser rewrites the request and changes the request method to options in compliance to the cross site origin(CORS) policy that took effect in 2014.

about 4 years ago · Juan Pablo Isaza Report

0

In addition to @john mba’s answer you should add mode: “cors” to your options

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!